package c.c.b.a.b.a.k;

import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;

/* compiled from: OkHostnameVerifier */
public final class e implements HostnameVerifier {
    public static final e a = new e();

    public static List<String> a(X509Certificate x509Certificate) {
        List b = b(x509Certificate, 7);
        List b2 = b(x509Certificate, 2);
        ArrayList arrayList = new ArrayList(b2.size() + b.size());
        arrayList.addAll(b);
        arrayList.addAll(b2);
        return arrayList;
    }

    public static List<String> b(X509Certificate x509Certificate, int i) {
        ArrayList arrayList = new ArrayList();
        try {
            Collection<List> subjectAlternativeNames = x509Certificate.getSubjectAlternativeNames();
            if (subjectAlternativeNames == null) {
                return Collections.emptyList();
            }
            for (List list : subjectAlternativeNames) {
                if (list != null) {
                    if (list.size() >= 2) {
                        Integer num = (Integer) list.get(0);
                        if (num != null) {
                            if (num.intValue() == i) {
                                String str = (String) list.get(1);
                                if (str != null) {
                                    arrayList.add(str);
                                }
                            }
                        }
                    }
                }
            }
            return arrayList;
        } catch (CertificateParsingException unused) {
            return Collections.emptyList();
        }
    }

    public boolean c(String str, String str2) {
        if (!(str == null || str.length() == 0)) {
            String str3 = ".";
            if (!str.startsWith(str3)) {
                String str4 = "..";
                if (!(str.endsWith(str4) || str2 == null || str2.length() == 0 || str2.startsWith(str3) || str2.endsWith(str4))) {
                    if (!str.endsWith(str3)) {
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.append(str);
                        stringBuilder.append('.');
                        str = stringBuilder.toString();
                    }
                    if (!str2.endsWith(str3)) {
                        StringBuilder stringBuilder2 = new StringBuilder();
                        stringBuilder2.append(str2);
                        stringBuilder2.append('.');
                        str2 = stringBuilder2.toString();
                    }
                    str2 = str2.toLowerCase(Locale.US);
                    if (!str2.contains("*")) {
                        return str.equals(str2);
                    }
                    str3 = "*.";
                    if (!str2.startsWith(str3) || str2.indexOf(42, 1) != -1 || str.length() < str2.length() || str3.equals(str2)) {
                        return false;
                    }
                    str2 = str2.substring(1);
                    if (!str.endsWith(str2)) {
                        return false;
                    }
                    int length = str.length() - str2.length();
                    if (length <= 0 || str.lastIndexOf(46, length - 1) == -1) {
                        return true;
                    }
                    return false;
                }
            }
        }
        return false;
    }

    /* JADX WARNING: Missing block: B:51:0x0125, code skipped:
            r3 = r2.g;
            r4 = r2.d;
            r1 = new java.lang.String(r3, r4, r2.f - r4);
     */
    /* JADX WARNING: Missing block: B:78:0x0188, code skipped:
            r2.e = r1;
     */
    public boolean d(java.lang.String r13, java.security.cert.X509Certificate r14) {
        /*
        r12 = this;
        r0 = c.c.b.a.b.a.e.q;
        r0 = r0.matcher(r13);
        r0 = r0.matches();
        r1 = 0;
        if (r0 == 0) goto L_0x0029;
    L_0x000d:
        r0 = 7;
        r14 = b(r14, r0);
        r0 = r14.size();
        r2 = 0;
    L_0x0017:
        if (r2 >= r0) goto L_0x02a1;
    L_0x0019:
        r3 = r14.get(r2);
        r3 = (java.lang.String) r3;
        r3 = r13.equalsIgnoreCase(r3);
        if (r3 == 0) goto L_0x0026;
    L_0x0025:
        goto L_0x0048;
    L_0x0026:
        r2 = r2 + 1;
        goto L_0x0017;
    L_0x0029:
        r0 = java.util.Locale.US;
        r13 = r13.toLowerCase(r0);
        r0 = 2;
        r2 = b(r14, r0);
        r3 = r2.size();
        r4 = 0;
        r5 = 0;
    L_0x003a:
        if (r4 >= r3) goto L_0x004f;
    L_0x003c:
        r5 = r2.get(r4);
        r5 = (java.lang.String) r5;
        r5 = r12.c(r13, r5);
        if (r5 == 0) goto L_0x004b;
    L_0x0048:
        r1 = 1;
        goto L_0x02a1;
    L_0x004b:
        r4 = r4 + 1;
        r5 = 1;
        goto L_0x003a;
    L_0x004f:
        if (r5 != 0) goto L_0x02a0;
    L_0x0051:
        r14 = r14.getSubjectX500Principal();
        r2 = new c.c.b.a.b.a.k.d;
        r2.m926init(r14);
        r2.c = r1;
        r2.d = r1;
        r2.e = r1;
        r2.f = r1;
        r14 = r2.a;
        r14 = r14.toCharArray();
        r2.g = r14;
        r14 = r2.b();
        if (r14 != 0) goto L_0x0072;
    L_0x0070:
        goto L_0x021f;
    L_0x0072:
        r1 = r2.c;
        r3 = r2.b;
        if (r1 != r3) goto L_0x007a;
    L_0x0078:
        goto L_0x021f;
    L_0x007a:
        r4 = r2.g;
        r4 = r4[r1];
        r5 = 92;
        r6 = "Unexpected end of DN: ";
        r7 = 34;
        r8 = 32;
        r9 = 59;
        r10 = 44;
        r11 = 43;
        if (r4 == r7) goto L_0x01db;
    L_0x008e:
        r7 = 35;
        if (r4 == r7) goto L_0x0137;
    L_0x0092:
        if (r4 == r11) goto L_0x0133;
    L_0x0094:
        if (r4 == r10) goto L_0x0133;
    L_0x0096:
        if (r4 == r9) goto L_0x0133;
    L_0x0098:
        r2.d = r1;
        r2.e = r1;
    L_0x009c:
        r1 = r2.c;
        r3 = r2.b;
        if (r1 < r3) goto L_0x00b0;
    L_0x00a2:
        r1 = new java.lang.String;
        r3 = r2.g;
        r4 = r2.d;
        r5 = r2.e;
        r5 = r5 - r4;
        r1.<init>(r3, r4, r5);
        goto L_0x0210;
    L_0x00b0:
        r3 = r2.g;
        r4 = r3[r1];
        if (r4 == r8) goto L_0x00ee;
    L_0x00b6:
        if (r4 == r9) goto L_0x00e0;
    L_0x00b8:
        if (r4 == r5) goto L_0x00cd;
    L_0x00ba:
        if (r4 == r11) goto L_0x00e0;
    L_0x00bc:
        if (r4 == r10) goto L_0x00e0;
    L_0x00be:
        r4 = r2.e;
        r6 = r4 + 1;
        r2.e = r6;
        r6 = r3[r1];
        r3[r4] = r6;
        r1 = r1 + 1;
        r2.c = r1;
        goto L_0x009c;
    L_0x00cd:
        r1 = r2.e;
        r4 = r1 + 1;
        r2.e = r4;
        r4 = r2.c();
        r3[r1] = r4;
        r1 = r2.c;
        r1 = r1 + 1;
        r2.c = r1;
        goto L_0x009c;
    L_0x00e0:
        r1 = new java.lang.String;
        r3 = r2.g;
        r4 = r2.d;
        r5 = r2.e;
        r5 = r5 - r4;
        r1.<init>(r3, r4, r5);
        goto L_0x0210;
    L_0x00ee:
        r4 = r2.e;
        r2.f = r4;
        r1 = r1 + 1;
        r2.c = r1;
        r1 = r4 + 1;
        r2.e = r1;
        r3[r4] = r8;
    L_0x00fc:
        r1 = r2.c;
        r3 = r2.b;
        if (r1 >= r3) goto L_0x0115;
    L_0x0102:
        r4 = r2.g;
        r6 = r4[r1];
        if (r6 != r8) goto L_0x0115;
    L_0x0108:
        r3 = r2.e;
        r6 = r3 + 1;
        r2.e = r6;
        r4[r3] = r8;
        r1 = r1 + 1;
        r2.c = r1;
        goto L_0x00fc;
    L_0x0115:
        if (r1 == r3) goto L_0x0125;
    L_0x0117:
        r3 = r2.g;
        r4 = r3[r1];
        if (r4 == r10) goto L_0x0125;
    L_0x011d:
        r4 = r3[r1];
        if (r4 == r11) goto L_0x0125;
    L_0x0121:
        r1 = r3[r1];
        if (r1 != r9) goto L_0x009c;
    L_0x0125:
        r1 = new java.lang.String;
        r3 = r2.g;
        r4 = r2.d;
        r5 = r2.f;
        r5 = r5 - r4;
        r1.<init>(r3, r4, r5);
        goto L_0x0210;
    L_0x0133:
        r1 = "";
        goto L_0x0210;
    L_0x0137:
        r4 = r1 + 4;
        if (r4 >= r3) goto L_0x01c8;
    L_0x013b:
        r2.d = r1;
        r1 = r1 + 1;
        r2.c = r1;
    L_0x0141:
        r1 = r2.c;
        r3 = r2.b;
        if (r1 == r3) goto L_0x0188;
    L_0x0147:
        r3 = r2.g;
        r4 = r3[r1];
        if (r4 == r11) goto L_0x0188;
    L_0x014d:
        r4 = r3[r1];
        if (r4 == r10) goto L_0x0188;
    L_0x0151:
        r4 = r3[r1];
        if (r4 != r9) goto L_0x0156;
    L_0x0155:
        goto L_0x0188;
    L_0x0156:
        r4 = r3[r1];
        if (r4 != r8) goto L_0x0171;
    L_0x015a:
        r2.e = r1;
        r1 = r1 + 1;
        r2.c = r1;
    L_0x0160:
        r1 = r2.c;
        r3 = r2.b;
        if (r1 >= r3) goto L_0x018a;
    L_0x0166:
        r3 = r2.g;
        r3 = r3[r1];
        if (r3 != r8) goto L_0x018a;
    L_0x016c:
        r1 = r1 + 1;
        r2.c = r1;
        goto L_0x0160;
    L_0x0171:
        r4 = r3[r1];
        r5 = 65;
        if (r4 < r5) goto L_0x0183;
    L_0x0177:
        r4 = r3[r1];
        r5 = 70;
        if (r4 > r5) goto L_0x0183;
    L_0x017d:
        r4 = r3[r1];
        r4 = r4 + r8;
        r4 = (char) r4;
        r3[r1] = r4;
    L_0x0183:
        r1 = r1 + 1;
        r2.c = r1;
        goto L_0x0141;
    L_0x0188:
        r2.e = r1;
    L_0x018a:
        r1 = r2.e;
        r3 = r2.d;
        r1 = r1 - r3;
        r4 = 5;
        if (r1 < r4) goto L_0x01b5;
    L_0x0192:
        r4 = r1 & 1;
        if (r4 == 0) goto L_0x01b5;
    L_0x0196:
        r4 = r1 / 2;
        r5 = new byte[r4];
        r3 = r3 + 1;
        r6 = 0;
    L_0x019d:
        if (r6 >= r4) goto L_0x01aa;
    L_0x019f:
        r7 = r2.a(r3);
        r7 = (byte) r7;
        r5[r6] = r7;
        r3 = r3 + r0;
        r6 = r6 + 1;
        goto L_0x019d;
    L_0x01aa:
        r3 = new java.lang.String;
        r4 = r2.g;
        r5 = r2.d;
        r3.<init>(r4, r5, r1);
        r1 = r3;
        goto L_0x0210;
    L_0x01b5:
        r13 = new java.lang.IllegalStateException;
        r14 = c.b.a.a.a.g(r6);
        r0 = r2.a;
        r14.append(r0);
        r14 = r14.toString();
        r13.<init>(r14);
        throw r13;
    L_0x01c8:
        r13 = new java.lang.IllegalStateException;
        r14 = c.b.a.a.a.g(r6);
        r0 = r2.a;
        r14.append(r0);
        r14 = r14.toString();
        r13.<init>(r14);
        throw r13;
    L_0x01db:
        r1 = r1 + 1;
        r2.c = r1;
        r2.d = r1;
        r2.e = r1;
    L_0x01e3:
        r1 = r2.c;
        r3 = r2.b;
        if (r1 == r3) goto L_0x028d;
    L_0x01e9:
        r3 = r2.g;
        r4 = r3[r1];
        if (r4 != r7) goto L_0x026c;
    L_0x01ef:
        r1 = r1 + 1;
        r2.c = r1;
    L_0x01f3:
        r1 = r2.c;
        r3 = r2.b;
        if (r1 >= r3) goto L_0x0204;
    L_0x01f9:
        r3 = r2.g;
        r3 = r3[r1];
        if (r3 != r8) goto L_0x0204;
    L_0x01ff:
        r1 = r1 + 1;
        r2.c = r1;
        goto L_0x01f3;
    L_0x0204:
        r1 = new java.lang.String;
        r3 = r2.g;
        r4 = r2.d;
        r5 = r2.e;
        r5 = r5 - r4;
        r1.<init>(r3, r4, r5);
    L_0x0210:
        r3 = "cn";
        r14 = r3.equalsIgnoreCase(r14);
        if (r14 == 0) goto L_0x0219;
    L_0x0218:
        goto L_0x0220;
    L_0x0219:
        r14 = r2.c;
        r1 = r2.b;
        if (r14 < r1) goto L_0x0228;
    L_0x021f:
        r1 = 0;
    L_0x0220:
        if (r1 == 0) goto L_0x02a0;
    L_0x0222:
        r1 = r12.c(r13, r1);
        goto L_0x02a1;
    L_0x0228:
        r1 = r2.g;
        r3 = r1[r14];
        r4 = "Malformed DN: ";
        if (r3 == r10) goto L_0x024d;
    L_0x0230:
        r3 = r1[r14];
        if (r3 != r9) goto L_0x0235;
    L_0x0234:
        goto L_0x024d;
    L_0x0235:
        r1 = r1[r14];
        if (r1 != r11) goto L_0x023a;
    L_0x0239:
        goto L_0x024d;
    L_0x023a:
        r13 = new java.lang.IllegalStateException;
        r14 = c.b.a.a.a.g(r4);
        r0 = r2.a;
        r14.append(r0);
        r14 = r14.toString();
        r13.<init>(r14);
        throw r13;
    L_0x024d:
        r14 = r14 + 1;
        r2.c = r14;
        r14 = r2.b();
        if (r14 == 0) goto L_0x0259;
    L_0x0257:
        goto L_0x0072;
    L_0x0259:
        r13 = new java.lang.IllegalStateException;
        r14 = c.b.a.a.a.g(r4);
        r0 = r2.a;
        r14.append(r0);
        r14 = r14.toString();
        r13.<init>(r14);
        throw r13;
    L_0x026c:
        r4 = r3[r1];
        if (r4 != r5) goto L_0x0279;
    L_0x0270:
        r1 = r2.e;
        r4 = r2.c();
        r3[r1] = r4;
        goto L_0x027f;
    L_0x0279:
        r4 = r2.e;
        r1 = r3[r1];
        r3[r4] = r1;
    L_0x027f:
        r1 = r2.c;
        r1 = r1 + 1;
        r2.c = r1;
        r1 = r2.e;
        r1 = r1 + 1;
        r2.e = r1;
        goto L_0x01e3;
    L_0x028d:
        r13 = new java.lang.IllegalStateException;
        r14 = c.b.a.a.a.g(r6);
        r0 = r2.a;
        r14.append(r0);
        r14 = r14.toString();
        r13.<init>(r14);
        throw r13;
    L_0x02a0:
        r1 = 0;
    L_0x02a1:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.c.b.a.b.a.k.e.d(java.lang.String, java.security.cert.X509Certificate):boolean");
    }

    public boolean verify(String str, SSLSession sSLSession) {
        try {
            return d(str, (X509Certificate) sSLSession.getPeerCertificates()[0]);
        } catch (SSLException unused) {
            return false;
        }
    }
}
